<?php
class Warna extends CI_Controller{
    function  __construct() {
        parent::__construct();
        $this->load->model('Warna_model');
	$this->load->helper(array('form', 'url'));
	$this->load->library('form_validation');
      }

	function index($offset=''){

	$data['warna'] = $this->Warna_model->getWarna();

        $this->load->view('admin_views/warna/warna', $data);
    }

	function add()
	{
		$this->form_validation->set_rules('strwarna', 'Warna', 'trim|required|xss_clean');

		$this->form_validation->set_message('required', ' %s tidak boleh kosong !!');

		if ($this->form_validation->run() == FALSE)
		 {
                       $this->load->view('admin_views/warna/add');
		}else{

                        $this->Warna_model->insert($_POST);
			redirect('warna/warna');
                }
	}

      function edit($intid_warna)
		{
			if($_POST==NULL)
			{

				$datawarna = $this->Warna_model->select($intid_warna);
				foreach ($datawarna as $g)
				{
					$data['intid_warna']	 	= $g->intid_warna;
					$data['strwarna'] 		= $g->strwarna;
				}
				$this->load->view('admin_views/warna/edit', $data);
			}else {
				$this->Warna_model->update($intid_warna);
				redirect('warna/index');
			}

		}


    function delete($intid_warna)
	{
		$this->Warna_model->delete($intid_warna);
		redirect('warna/warna');
	}

}
?>
